//
//  HYOUWebViewController.m
//  BestGift
//
//  Created by 温晓宇 on 16/1/4.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "HYOUWebViewController.h"
#import "UMSocial.h"
@interface HYOUWebViewController ()<UIScrollViewDelegate>

//@property(nonatomic, retain) UIScrollView *scroll;

@property(nonatomic, retain)UIWebView *webView;

@property(nonatomic, retain) UITableView *btn_tableView;

//@property(nonatomic, retain) UIImageView *imageView;
//@property(nonatomic, retain) UILabel *nameLabel;


@end

@implementation HYOUWebViewController
-(void)dealloc{
//    [_scroll release];
    [_image release];
    [_url release];
    [_name release];
//    [_imageView release];
//    [_nameLabel release];
    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.navigationItem.title = @"攻略详情";
    
    UIImage *image = [[UIImage imageNamed:@"iconfont-shoucang"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:image style:UIBarButtonItemStylePlain target:self action:@selector(rightAction:)];
    
//    UIView *collect = [[UIView alloc]initWithFrame:CGRectMake(0, 64, WIDTH, 50)];
//    collect.backgroundColor = [UIColor redColor];
//    [self.view addSubview:collect];
//    
//    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
//    button.frame = CGRectMake(WIDTH - 50, 64, 50, 50);
//    [button setTitle:@"收藏" forState:UIControlStateNormal];
//    button.backgroundColor = [UIColor blackColor];
//    [self.view addSubview:button];
    
    
//    self.scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 200)];
//    self.scroll.backgroundColor = [UIColor whiteColor];
//    [self.view addSubview:self.scroll];
////    self.scroll.delegate = self;
//    
//    self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 200)];
//    NSURL *urlImage = [NSURL URLWithString:self.image];
//    [self.imageView sd_setImageWithURL:urlImage];
//    [self.imageView release];
//    [self.scroll addSubview:self.imageView];
//    
//    self.nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, self.imageView.frame.size.height - 50, WIDTH, 50)];
//    self.nameLabel.backgroundColor = [UIColor redColor];
//    self.nameLabel.text = self.name;
//    self.nameLabel.textColor = [UIColor whiteColor];
//    self.nameLabel.font = [UIFont systemFontOfSize:20];
//    [self.imageView addSubview:self.nameLabel];
    
    self.webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT - 64)];
//    [self.webView.scrollView addSubview:self.scroll];
    NSString *string = self.url;
    NSURL *url = [NSURL URLWithString:string];
    NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
    [self.webView loadRequest:request];
    [self.view addSubview:self.webView];
    [_webView release];
    
//    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"back_nav"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStyleDone target:self action:
}
//-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
//    
//    NSLog(@"scrollViewDidScroll");
//    CGPoint point=scrollView.contentOffset;
//    NSLog(@"%f,%f",point.x,point.y);
//    // 从中可以读取contentOffset属性以确定其滚动到的位置。
//    
//    // 注意：当ContentSize属性小于Frame时，将不会出发滚动
//}
-(void)rightAction:(UIBarButtonItem *)btn{
//    [UMSocialSnsService presentSnsIconSheetView:self
//                                         appKey:@"568dcee0e0f55afe6f001e85"
//                                      shareText:[NSString stringWithFormat:@"攻略很不错~~%@",self.url]
//                                     shareImage:[UIImage imageNamed:@"icon.png"]
//                                shareToSnsNames:nil
//                                       delegate:nil];
    BOOL flag = NO;
    NSMutableArray *array = [[HYOUSingleton shareDataSingleton] selectHomeCell];
    for (HYOUOneCellModel *model in array) {
        NSLog(@"%@",model.title);
        if ([model.title isEqualToString:self.name]) {
            flag = YES;
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"已被收藏" preferredStyle:UIAlertControllerStyleAlert];
            UIAlertAction *ok = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];
            [alert addAction:ok];
            [self presentViewController:alert animated:YES completion:^{
                
            }];
        }
    }
    if (flag == NO) {
        NSLog(@"收藏成功");
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"收藏成功" preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *ok = [UIAlertAction actionWithTitle:@"好的" style:UIAlertActionStyleDefault handler:nil];
        [alert addAction:ok];
        [self presentViewController:alert animated:YES completion:^{
            HYOUOneCellModel *model = [[HYOUOneCellModel alloc] init];
            model.title = self.name;
            model.content_url = self.url;
            model.cover_image_url = self.image;
            [[HYOUSingleton shareDataSingleton] insertHomeCellIntoTable:model];
        }];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
